﻿(function (window, $) {
    var tabsCount = {
        login: 1,
        function: 1,
        diagnosis:1
    }
    function addNewTab(ctx) {
        var filterStr = ctx.dataset.log;
        switch (filterStr) {
            case "login":
                addLoginLog();
                break;
            case "function":
                addFunctionLog();
                break;
            case "diagnosis":
                addDiagnosisLog();
                break;
        }
    }
    var $tabs = $("#tabs");

    function addLoginLog() {
        var i = tabsCount.login;
        var selector = 'login-' + i;
        $tabs.tabs('add', {
            title: '登录日志' + i,
            seleted: true,
            content: '<div id="' + selector + '"></div>',
            closable: true,
            selector: selector
        })
        tabsCount.login += 1;
        initLoginDataGrid(selector);
    }

    function addFunctionLog() {
        var i = tabsCount.login;
        var selector = 'function-' + i;
        $tabs.tabs('add', {
            title: '功能日志' + tabsCount.function,
            seleted: true,
            content: '<div id="' + selector + '"></div>',
            closable: true
        })
        tabsCount.function += 1;
    }
    function addDiagnosisLog() {
        var i = tabsCount.login;
        var selector = 'diagnosis-' + i;
        $tabs.tabs('add', {
            title: '诊断日志' + tabsCount.function,
            seleted: true,
            content: '<div id="' + selector + '"></div>',
            closable: true
        })
        tabsCount.function += 1;
    }
    //function getTabContent(id) {
    //    var container = $('<div id="' + id + '"></div>');
    //    var condition = $('<div class="condition">' +
                            
    //                      '</div > ')
    //    var datagrid = $('<div class="datagrid"></div>');
    //}
    function initLoginDataGrid(selector) {
        $('#' + selector).datagrid({
            columns: [[
                {
                    field: 'userName', title: '用户名', width: '20%'
                },
                {
                    field: 'userType', title: '用户类型', width: '20%'
                },
                {
                    field: 'time', title: '登录时间', width: '20%'
                },
                {
                    field: 'ip', title: 'IP', width: '20%'
                },
                {
                    field: 'remark', title: '备注', width: '20%'
                }

            ]],
        });
        $.getJSON(location.origin + "/LoginLog/GetAllLoginRecordData").then(data => {
            $('#' + selector).datagrid('loadData', data)
        });
    }
    function initFunctionDataGrid() {

    }
    function initDiagnosisGrid() {

    }
    window.addNewTab = addNewTab;
})(window, jQuery);